package models.general;

import play.db.ebean.Model;

import javax.persistence.Entity;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kristborga
 * Date: 5.5.2013
 * Time: 11:39
 * To change this template use File | Settings | File Templates.
 */
@Entity
public class vAfangarBaekur extends Model {
    private Integer bok_id;
    private Integer afangi_id;
    private String heiti;
    private String hofundur;
    private String utgafa;
    private String utgefandi;

    public static Finder<Integer,vAfangarBaekur> find = new Finder<Integer,vAfangarBaekur>(
            Integer.class, vAfangarBaekur.class
    );
    public static List<vAfangarBaekur> findAllByAfangiID(int afangi_id){
        return vAfangarBaekur.find.where().eq("afangi_id", afangi_id).findList();
    }

    public static List<vAfangarBaekur> getAllBaekurByList(List<vNemandiAfangarOnn> courses){
        List<vAfangarBaekur> returnBooks = new ArrayList<vAfangarBaekur>();
        for(vNemandiAfangarOnn single:courses){
            List<vAfangarBaekur> temp = vAfangarBaekur.find.where().eq("afangi_id", single.afangi_id).findList();
            returnBooks.addAll(temp);
        }
     return returnBooks;
    }
    public static List<vAfangarBaekur> findAll(){
        return vAfangarBaekur.find.all();
    }

    public Integer getBok_id() {
        return bok_id;
    }

    public void setBok_id(Integer bok_id) {
        this.bok_id = bok_id;
    }

    public Integer getAfangi_id() {
        return afangi_id;
    }

    public void setAfangi_id(Integer afangi_id) {
        this.afangi_id = afangi_id;
    }

    public String getHeiti() {
        return heiti;
    }

    public void setHeiti(String heiti) {
        this.heiti = heiti;
    }

    public String getHofundur() {
        return hofundur;
    }

    public void setHofundur(String hofundur) {
        this.hofundur = hofundur;
    }

    public String getUtgafa() {
        return utgafa;
    }

    public void setUtgafa(String utgafa) {
        this.utgafa = utgafa;
    }

    public String getUtgefandi() {
        return utgefandi;
    }

    public void setUtgefandi(String utgefandi) {
        this.utgefandi = utgefandi;
    }

    public static List<vAfangarBaekur> getBokFromId(Integer bok_id){
        return vAfangarBaekur.find.where().eq("bok_id", bok_id).where().findList();
    }

    //gets all books for courses the teachere is teaching this semsester
    public static List<vAfangarBaekur> getAllBooksByAfangarId(List<vKennariHoparOnn> courses){
        List<vAfangarBaekur> books = new ArrayList<vAfangarBaekur>();
        for(vKennariHoparOnn course:courses){
            List<vAfangarBaekur> temp = find.where().eq("afangi_id", course.getAfangi_id()).findList();
            for(vAfangarBaekur single:temp){
                books.add(single);
            }
        }
        return books;
    }
}
